<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/tags.jsp"%>
<aos:html>
<aos:head title="物料管理列表">
	<aos:include lib="ext" />
	<aos:base href="console/material" />
</aos:head>
<aos:body>
</aos:body>
<aos:onready>
	<aos:viewport layout="border">
		<aos:formpanel id="qform" labelWidth="70" region="north"
			header="false" padding="5 0 0 0" border="false">
			<aos:textfield fieldLabel="物料名称" name="material_name" />
			<aos:button width="80" text="查 询" margin="0 0 0 15px"
				icon="search.png" onclick="query"></aos:button>
			<aos:button width="80" text="重 置" margin="0 0 0 15px"
				icon="refresh1.png" onclick="AOS.reset(qform)"></aos:button>
		</aos:formpanel>
		<aos:gridpanel id="grid" url="list" onrender="query"
			onitemdblclick="show_update" region="center">
			<aos:docked>
				<aos:dockeditem onclick="show_add" text="新增物料" icon="add.png" />
				<aos:dockeditem onclick="show_update" text="修改物料" icon="edit.png" />
			</aos:docked>
			<aos:selmodel type="checkbox" mode="multi" />
			<aos:column type="rowno" header="序号" width="40" />
			<aos:column header="id" dataIndex="id" width="40" hidden="true"/>
			<aos:column header="物料名称" dataIndex="material_name" width="60" />
			<aos:column header="库存数量" dataIndex="stock" width="60" />
			<aos:column header="已购数量" dataIndex="sold" width="60" />
			<aos:column header="单价" dataIndex="price" width="60" />
			<aos:column header="上架？" dataIndex="state" width="60"
				rendererFn="state_ren" />
		</aos:gridpanel>

		<aos:window id="add_w" title="新增物料" maxHeight="-10" autoScroll="true">
			<aos:formpanel id="add_f" width="420" layout="anchor" labelWidth="80">
				<aos:textfield name="material_name" fieldLabel="物料名称"
					allowBlank="false" />
				<aos:textfield name="stock" fieldLabel="库存数量"
					allowBlank="false" />
				<aos:textfield name="price" fieldLabel="单价"
					allowBlank="false" />
				<aos:radioboxgroup fieldLabel="状态" columns="[50,50]">
					<aos:radiobox name="state" boxLabel="上架" inputValue="0"
						checked="true" />
					<aos:radiobox name="state" boxLabel="下架" inputValue="1" />
				</aos:radioboxgroup>
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="add" text="保存" icon="ok.png" />
				<aos:dockeditem onclick="#add_w.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>
		<aos:window id="update_w" title="修改物料信息" maxHeight="-10"
			autoScroll="true">
			<aos:formpanel id="update_f" width="420" layout="anchor"
				labelWidth="80">
				<aos:textfield name="id" fieldLabel="ID" allowBlank="false"
					readOnly="true" />
				<aos:textfield name="material_name" fieldLabel="物料名称"
					allowBlank="false" />
				<aos:textfield name="stock" fieldLabel="库存数量"
					allowBlank="false" />
				<aos:textfield name="price" fieldLabel="单价"
					allowBlank="false" />
				<aos:radioboxgroup fieldLabel="状态" columns="[50,50]">
					<aos:radiobox name="state" boxLabel="上架" inputValue="0"
						checked="true" />
					<aos:radiobox name="state" boxLabel="下架" inputValue="1" />
				</aos:radioboxgroup>
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="update" text="修改" icon="ok.png" />
				<aos:dockeditem onclick="#update_w.hide();" text="关闭"
					icon="close.png" />
			</aos:docked>
		</aos:window>
	</aos:viewport>

	<script type="text/javascript">
    
    function state_ren(v){
		if(v == 0){
			return '是'
		}else if(v == 1){
			return '否'
		}else{
			return v
		}
	}
   

   	 
    function query(){
        grid_store.getProxy().extraParams = qform.getValues();
        grid_store.getProxy().getMethod = function(){ return 'POST'; }
        grid_store.load();
     }

	function show_add(){
		AOS.reset(add_f);
        add_w.show();
	}
	
	function add(){
		AOS.ajax({
            forms : add_f,
            url : 'add',
            ok : function(data) {
                	if(data.success){
                		 add_w.hide();
                     grid_store.reload();
                	}
                AOS.tip(data.appmsg);
            }
        }); 
	}
    function show_update(){
        AOS.reset(update_f);
        grid_store.reload();           
        var record = AOS.selectone(grid);
        grid.getSelectionModel().clearSelections();
        if(record){
            update_w.show();
            update_f.loadRecord(record);
        }
    }        
    
    function update(){
           AOS.ajax({
            forms : update_f,
            url : 'update',
            ok : function(data) {
                	if(data.success){
                		update_w.hide();
                    grid_store.reload();
                    grid.getSelectionModel().clearSelections()
                	}
                	AOS.tip(data.appmsg);
            }
        }); 
    }
    </script>
</aos:onready>
</aos:html>